"use strict";
const mysql = require('mysql'),
  async = require("async");

// 导出mysql的select方法
exports.select = (sql, parameter) => {
  let promise = new Promise(function(resolve,reject) {
    let result = null;
    let mysql = require('mysql');
    let connection = mysql.createConnection({
      host     : 'localhost',
      user     : 'root',
      password : '123456',
    //   password : 'Likaiji19950728@',
      port: '3306',
      database: 'boko',
      // database: 'boko_los',
    });
    connection.connect();
    connection.query(sql, parameter , function (err, results, fields) {
        if (err) {
          console.log("err");
          reject(err);
        }else {
          // console.log(results);
          resolve({status: 200, result:results});
          // if(results.length > 0) {
          //   resolve({status: 200, result:results});
          // }else {
          //   resolve({status: 200, error:results});
          // }
        }
      }
    );
    connection.end();
  });
  return promise;
}
